package com.itheima.controller;

import com.itheima.anno.Log;
import com.itheima.pojo.Clazz;
import com.itheima.pojo.EmpQueryParam;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/clazzs")
public class ClazzController {

    @Autowired
    private ClazzService clazzService;


    @GetMapping
    public Result page(EmpQueryParam empQueryParam){
        log.info("分页查询,参数:{}",empQueryParam);
        PageResult  pageResult=clazzService.page(empQueryParam);
        return Result.success(pageResult);
    }

    @Log
    @DeleteMapping("{id}")
    public Result delete(@PathVariable Integer id){
        log.info("删除班级,id:{}",id);
        clazzService.deleteById(id);
        return Result.success();
    }

    @Log
    @PostMapping
    public Result add(@RequestBody Clazz clazz){
        log.info("添加班级");
        clazzService.add(clazz);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id){
        log.info("查询班级id为:{}",id);
        Clazz clazz=clazzService.getInfo(id);
        return Result.success(clazz);
    }

    @Log
    @PutMapping
    public Result update(@RequestBody Clazz clazz){
        log.info("修改班级信息:{}",clazz);
        clazzService.update(clazz);
        return Result.success();
    }






}
